import QtQuick
import QtQuick.Controls
import "qrc:/component/ZGlobal.js" as Global
Item{
    anchors.fill: parent
    // Rectangle{
    //     x:0;y:0;width:100;height: 100;
    //     color:"red"
    // }
    property var motorModel :
        [
            { text: "(Alice)", defaultInput: "一天" },
            { text: "(Bob)", defaultInput: "二天"},
            { text: "(Charlie)", defaultInput: "三天" },
        ]

    property var motorModel1 :
        [
            { text: "(张三)", defaultInput: "一天" },
            { text: "(李四)", defaultInput: "二天"},
            { text: "(王五)", defaultInput: "三天" },
            { text: "(赵六)", defaultInput: "三天" },
        ]
    property int selected: 0

    Row{
        spacing: 10
        Repeater {
            id: repeater
            // model: ListModel {
            //     ListElement { name: "Alice"; role: "Developer" }
            //     ListElement { name: "Bob"; role: "Designer" }
            //     ListElement { name: "Charlie"; role: "Manager" }
            // }
            // delegate: TestBlueBox{
            //     width:100;height: 30
            //     text: index
            // }
            model: selected ===0 ? motorModel:motorModel1
            TestBlueBox{
                width:100;height: 30
                text: modelData.text + index
                onClicked: {
                    // console.log(">>>>>>>>>>>>>>>", modelData.text, "<<<", motorModel[index].text);
                    //selected = !selected;
                    motorModel[index].text="pppp"
                    // console.log(">>>>>>>>>>>>>>>", modelData.text, "<<<", motorModel[index].text);
                    // var mask = Global.createModel(root);

                }
            }

        }
    }

    Rectangle {
        id: timer
        x:300
        y:300
        width: 200
        height: 200
        color: "white"

        property int count: 10

        Column {
            anchors.centerIn: parent
            spacing: 20

            Text {
                text: timer.count > 0 ? timer.count : "完成!"
                font.pixelSize: 30
                anchors.horizontalCenter: parent.horizontalCenter
            }

            Button {
                text: "开始倒计时"
                onClicked:{
                    timer.count = 10;
                    countdownTimer.start()
                }
                anchors.horizontalCenter: parent.horizontalCenter
            }
        }

        Timer {
            id: countdownTimer
            interval: 1000
            repeat: true
            onTriggered: timer.count > 0 ? timer.count-- : stop()
        }
    }
    Rectangle {
        x:500
        y:500
        width: 400
        height: 400
        color: "lightgray"

        // GIF动画 - 无限循环
        AnimatedImage {
            id: infiniteGif
            anchors.centerIn: parent
            width: 200
            height: 200
            source: "qrc:/assets/save-gift.gif"
            // loops: AnimatedImage.Infinite  // 无限循环
            playing: true
            property int playCount: 0
            property int maxPlayCount: 3  // 最大播放次数

            onCurrentFrameChanged: {
                // 检测是否播放到最后一帧
                if (currentFrame === frameCount - 1) {
                    //currentFrame = 0
                    console.log("已完成播放次数:", playCount)
                    // infiniteGif.palying=true;
                }
            }
        }

        // 控制面板
        Column {
            anchors.bottom: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            spacing: 10

            Button {
                text: infiniteGif.playing ? "暂停动画" : "播放动画"
                onClicked: infiniteGif.playing = !infiniteGif.playing
            }

            Button {
                text: "重置动画"
                onClicked: {
                    infiniteGif.currentFrame = 0  // 回到第一帧
                    //infiniteGif.playing = true
                }
            }

            Text {
                text: "当前帧: " + infiniteGif.currentFrame +
                      " / 总帧数: " + infiniteGif.frameCount
                horizontalAlignment: Text.AlignHCenter
            }
        }
    }

}

